package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.JyjcSharingExpensesSumExport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JyjcSharingExpensesSum;
import com.ruoyi.system.service.IJyjcSharingExpensesSumService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 财务收入支出统计Controller
 *
 * @author 石亚兵
 * @date 2025-07-12
 */
@RestController
@RequestMapping("/system/JyjcSharingExpensesSum")
public class JyjcSharingExpensesSumController extends BaseController
{
    @Autowired
    private IJyjcSharingExpensesSumService jyjcSharingExpensesSumService;

    /**
     * 查询财务收入支出统计列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        startPage();
        List<JyjcSharingExpensesSum> list = jyjcSharingExpensesSumService.selectJyjcSharingExpensesSumList(jyjcSharingExpensesSum);
        return getDataTable(list);
    }

    /**
     * 查询财务收入支出统计列表
     */
    @Anonymous
    @GetMapping("/alllist")
    public TableDataInfo alllist(JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        startPage();
        List<JyjcSharingExpensesSum> list = jyjcSharingExpensesSumService.alllist(jyjcSharingExpensesSum);
        return getDataTable(list);
    }
    @Anonymous
    @GetMapping("/allsumlist")
    public TableDataInfo allsumlist(JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        startPage();
        List<JyjcSharingExpensesSum> list = jyjcSharingExpensesSumService.allsumlist(jyjcSharingExpensesSum);
        return getDataTable(list);
    }
    /**
     * 查询财务收入支出统计列表
     */
    @Anonymous
    @GetMapping("/deptlist")
    public TableDataInfo deptlist(JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        startPage();
        List<JyjcSharingExpensesSum> list = jyjcSharingExpensesSumService.deptlist(jyjcSharingExpensesSum);
        return getDataTable(list);
    }

    /**
     * 查询财务收入支出统计列表
     */
    @Anonymous
    @GetMapping("/importalllist")
    public TableDataInfo importalllist(JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        startPage();
        List<JyjcSharingExpensesSum> list = jyjcSharingExpensesSumService.importalllist(jyjcSharingExpensesSum);
        return getDataTable(list);
    }
    @Anonymous
    @GetMapping("/importalllistsd")
    public TableDataInfo importalllistsd(JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        startPage();
        List<JyjcSharingExpensesSum> list = jyjcSharingExpensesSumService.importalllistsd(jyjcSharingExpensesSum);
        return getDataTable(list);
    }
    /**
     * 导出财务收入支出统计列表
     */
    @Anonymous
    @Log(title = "财务收入支出统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        List<JyjcSharingExpensesSumExport> list = jyjcSharingExpensesSumService.allsumlistExport(jyjcSharingExpensesSum);
        ExcelUtil<JyjcSharingExpensesSumExport> util = new ExcelUtil<JyjcSharingExpensesSumExport>(JyjcSharingExpensesSumExport.class);
        util.exportExcel(response, list, "收入成本汇总表");
    }

    /**
     * 获取财务收入支出统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:JyjcSharingExpensesSum:query')")
    @GetMapping(value = "/{deptname}")
    public AjaxResult getInfo(@PathVariable("deptname") String deptname)
    {
        return success(jyjcSharingExpensesSumService.selectJyjcSharingExpensesSumByDeptname(deptname));
    }

    /**
     * 新增财务收入支出统计
     */
    @PreAuthorize("@ss.hasPermi('system:JyjcSharingExpensesSum:add')")
    @Log(title = "财务收入支出统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        return toAjax(jyjcSharingExpensesSumService.insertJyjcSharingExpensesSum(jyjcSharingExpensesSum));
    }

    /**
     * 修改财务收入支出统计
     */
    @PreAuthorize("@ss.hasPermi('system:JyjcSharingExpensesSum:edit')")
    @Log(title = "财务收入支出统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JyjcSharingExpensesSum jyjcSharingExpensesSum)
    {
        return toAjax(jyjcSharingExpensesSumService.updateJyjcSharingExpensesSum(jyjcSharingExpensesSum));
    }

    @Anonymous
    @Log(title = "收支汇总", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<JyjcSharingExpensesSum> util = new ExcelUtil<JyjcSharingExpensesSum>(JyjcSharingExpensesSum.class);
        List<JyjcSharingExpensesSum> jyjcSharingExpensesSumList = util.importExcel(file.getInputStream());

        String message = jyjcSharingExpensesSumService.importJyjcSharingExpensesSum(jyjcSharingExpensesSumList, updateSupport);
        return success(message);
    }
    @Anonymous
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JyjcSharingExpensesSum> util = new ExcelUtil<JyjcSharingExpensesSum>(JyjcSharingExpensesSum.class);
        util.importTemplateExcel(response, "收支汇总数据");
    }
}
